package de.test.NeutrinoAndroidRemote.Tools;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

public class Downloader {
	
	public static String Get(String uri)
	{
		String resp = "";
		
        HttpClient client = new DefaultHttpClient();
        HttpGet request = new HttpGet(uri);
        try{
            HttpResponse response = client.execute(request);
            resp = Request(response);
        }catch(Exception ex){
            return null;
        }
		return resp;
	}
	
	public static String Request(HttpResponse response){
        String result = "";
        try{
            InputStream in = response.getEntity().getContent();
            BufferedReader reader = new BufferedReader(new InputStreamReader(in));
            StringBuilder str = new StringBuilder();
            String line = null;
            while((line = reader.readLine()) != null){
                str.append(line + "\n");
            }
            in.close();
            result = str.toString();
        }catch(Exception ex){
            result = "Error";
        }
        return result;
    }

}
